package com.turing.component;

import com.turing.entity.User;
import com.turing.mapper.UserMapper;
import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.Proxy;


public class MyFactoryBean implements FactoryBean {

	public Class getMapperInterFace() {
		return mapperInterFace;
	}

	public void setMapperInterFace(Class mapperInterFace) {
		this.mapperInterFace = mapperInterFace;
	}

	// 动态传进来
	private Class mapperInterFace;

	@Override
	public Object getObject() throws Exception {
		// DeptMapper
		return (UserMapper) Proxy.newProxyInstance(mapperInterFace.getClassLoader(), new Class[]{mapperInterFace}, (proxy, method, args1) -> {
			// 查询数据库...   mybatis
			System.out.println("查询");
			return new User();
		});
	}

	@Override
	public Class<?> getObjectType() {
		return mapperInterFace;
	}

	public MyFactoryBean() {
		System.out.println("加载");
	}
}
